package com.bstek.urule.springboot;

import com.bstek.urule.runtime.KnowledgePackage;
import com.bstek.urule.runtime.KnowledgeSession;
import com.bstek.urule.runtime.KnowledgeSessionFactory;
import com.bstek.urule.runtime.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Jacky.gao
 * @since 2019年5月16日
 */
@RestController
public class RuleTest {
	@Autowired
	private KnowledgeService service;

	@RequestMapping("/test")
	public String test() throws Exception{
		KnowledgePackage knowledgePackage=service.getKnowledge("3dxt-CXB/test");
        KnowledgeSession session=KnowledgeSessionFactory.newKnowledgeSession(knowledgePackage);
        session.fireRules();
        session.writeLogFile();
		return null;
	}

	@Resource
	JdbcTemplate jdbcTemplate;

	@ResponseBody
	@RequestMapping("/db")
	public  String getDb(){
		List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from test where 1=1"
				, new Object[]{});
		return "test表记录表："+list.size();
	}
}
